package net.da.client.common.config;

import java.util.HashMap;
import java.util.Map;

import net.da.client.component.HomeComponentDef;
import net.da.client.component.LoginComponentDef;
import net.da.client.component.MainComponentDef;
import net.da.client.component.TestComponentDef0;
import net.da.client.component.TestComponentDef1;
import net.da.client.component.TestComponentDef2;
import net.da.client.constants.DAConstants;

public class ConfigServiceImpl implements ConfigService {
	
	private static ConfigServiceImpl instance = new ConfigServiceImpl();
	private final Map values;
	
	private ConfigServiceImpl() {
		
		values = new HashMap();
		init();
	}
		 	
	private void init() {
		initComponentsDefinitions();		
	}

	private void initComponentsDefinitions() {
		
		ConfigKey key = ConfigKeyImpl.getInstance(DAConstants.COMPONENTS_NAMES.MAIN_COMPONENT);
		values.put(key, new MainComponentDef());
        key = ConfigKeyImpl.getInstance(DAConstants.COMPONENTS_NAMES.TEST_COMPONENT_0);
        values.put(key, new TestComponentDef0());
        key = ConfigKeyImpl.getInstance(DAConstants.COMPONENTS_NAMES.TEST_COMPONENT_1);
        values.put(key, new TestComponentDef1());
        key = ConfigKeyImpl.getInstance(DAConstants.COMPONENTS_NAMES.TEST_COMPONENT_2);
        values.put(key, new TestComponentDef2());        
        key = ConfigKeyImpl.getInstance(DAConstants.COMPONENTS_NAMES.HOME_COMPONENT);
        values.put(key, new HomeComponentDef());
        key = ConfigKeyImpl.getInstance(DAConstants.COMPONENTS_NAMES.LOGIN_COMPONENT);
        values.put(key, new LoginComponentDef());
		
	}

	public ConfigValue readConfigValue(ConfigKey configKey) {
				
		final Object value = values.get(configKey);
		return new ConfigValue() {

			public Object getVlaue() {
				return value;
			}		
		};		
	}
	
	
	public static ConfigServiceImpl getInstance() {
		return instance;
	}
	
	
	
	

}
